<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="css/mui.min.css">
		<style>
			html,
			body {
				background-color: #efeff4;
			}
			.mui-bar~.mui-content .mui-fullscreen {
				top: 44px;
				height: auto;
			}
			.mui-pull-top-tips {
				position: absolute;
				top: -20px;
				left: 50%;
				margin-left: -25px;
				width: 40px;
				height: 40px;
				border-radius: 100%;
				z-index: 1;
			}
			.mui-bar~.mui-pull-top-tips {
				top: 24px;
			}
			.mui-pull-top-wrapper {
				width: 42px;
				height: 42px;
				display: block;
				text-align: center;
				background-color: #efeff4;
				border: 1px solid #ddd;
				border-radius: 25px;
				background-clip: padding-box;
				box-shadow: 0 4px 10px #bbb;
				overflow: hidden;
			}
			.mui-pull-top-tips.mui-transitioning {
				-webkit-transition-duration: 200ms;
				transition-duration: 200ms;
			}
			.mui-pull-top-tips .mui-pull-loading {
				/*-webkit-backface-visibility: hidden;
				-webkit-transition-duration: 400ms;
				transition-duration: 400ms;*/
				
				margin: 0;
			}
			.mui-pull-top-wrapper .mui-icon,
			.mui-pull-top-wrapper .mui-spinner {
				margin-top: 7px;
			}
			.mui-pull-top-wrapper .mui-icon.mui-reverse {
				/*-webkit-transform: rotate(180deg) translateZ(0);*/
			}
			.mui-pull-bottom-tips {
				text-align: center;
				background-color: #efeff4;
				font-size: 15px;
				line-height: 40px;
				color: #777;
			}
			.mui-pull-top-canvas {
				overflow: hidden;
				background-color: #fafafa;
				border-radius: 40px;
				box-shadow: 0 4px 10px #bbb;
				width: 40px;
				height: 40px;
				margin: 0 auto;
			}
			.mui-pull-top-canvas canvas {
				width: 40px;
			}
			.mui-slider-indicator.mui-segmented-control {
				background-color: #efeff4;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">最新列表</h1>
		</header>
		<div class="mui-content">
			<div id="slider" class="mui-slider mui-fullscreen">
				<!--<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a class="mui-control-item mui-active" href="#item1mobile">
							推荐
						</a>
						<a class="mui-control-item" href="#item2mobile">
							热点
						</a>
						<a class="mui-control-item" href="#item3mobile">
							北京
						</a>
						 
					</div>
				</div>-->
				<div class="mui-slider-group">
					<div id="item1mobile" class="mui-slider-item mui-control-content mui-active">
						<div id="scroll1" class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<ul class="mui-table-view" id="xuanxiangka1">
									  
								</ul>
							</div>
						</div>
					</div>
					 
					 
					 
				</div>
			</div>
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/mui.pullToRefresh.js"></script>
		<script src="js/mui.pullToRefresh.material.js"></script>
		<script>
			mui.init({preloadPages:[{
				    id:'detail.html',
				    url:'detail.html'           
				 	}
			  	],});
			(function($) {
				//阻尼系数
				var deceleration = mui.os.ios?0.003:0.0009;
				var onid = '';  // 最新的上id
				var upid = '';  //下id
				var cate_id ='';
				
				var table = document.body.querySelector('#xuanxiangka1'); 
					mui.plusReady(function(){
						var self = plus.webview.currentWebview();
						  cate_id = self.cate_id;
						//alert(cate_id); 
						mui.ajax('http://029sj.cn/api.php?s=/News/index/',{
							data:{ 
								startlimit:0, 
								order:'asc', 
								cate_id:cate_id,
								limit:1,
								do:'up'
							},
							dataType:'json',//服务器返回json格式数据
							type:'get',//HTTP请求类型
							success:function(data){ 
								//获得服务器响应
								mui.each(data.msg, function (i, item) {
									var li = document.createElement('li');
									li.className = 'mui-table-view-cell';
									li.innerHTML = '<a class="mui-navigate-right" id="'+item.id+'"> '+item.title + '</a>';
									if(i==0  && onid=='' ) {
										onid = item.id; 
									}  
									upid = item.id;
									table.insertBefore(li, table.firstChild);
								});  
							}
						});
					}); 
				
				$('.mui-scroll-wrapper').scroll({
					bounce: false,
					indicators: true, //是否显示滚动条
					deceleration:deceleration
				});
				$.ready(function() {
					//循环初始化所有下拉刷新，上拉加载。
					$.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
						$(pullRefreshEl).pullToRefresh({ 
							down: {
								callback: function() {
									var self = this;
									setTimeout(function() { 
										
										createFragment('asc',10)
										
										self.endPullDownToRefresh(); 
									}, 1000);
								} 
							},
							up: {
								callback: function() {
									var self = this;
									setTimeout(function() {
										 
										createFragment('desc',10);
										
										self.endPullUpToRefresh();
									}, 1000);
								} 
							}
						});
					});
					var createFragment = function(order, limit) { 
					  
						mui.ajax('http://029sj.cn/api.php?s=/News/index/',{ 
							data:{  
								onid:onid,
								upid:upid,
								limit:limit,
								order:order, 
								cate_id:cate_id,
							},
							dataType:'json',//服务器返回json格式数据
							type:'get',//HTTP请求类型
							success:function(data){
								  
								var ul = document.body.querySelector('.mui-table-view');  
								var li; 
								//获得服务器响应
								mui.each(data.msg, function (i, item) {
									if(data.state){
										var li = document.createElement('li');
										li.className = 'mui-table-view-cell';
										li.innerHTML = '<a class="mui-navigate-right" href="info.html?id='+item.id+'" id="'+item.id+'"> '+item.title + (item.view) + '</a>';
									   	  
									   	 
									   	if(order=="asc"){
									   		onid = item.id;    
									   		ul.insertBefore(li,ul.firstChild);
									   	}else{ 
									   		upid = item.id; 
									   		ul.appendChild(li); 
									   	}
									}
									 
							    });  
							}
						});  
					};
					  
					 
					
					var detailPage = null; 
					//添加列表项的点击事件
					mui('.mui-table-view').on('tap', 'a', function(e) {
					  var id = this.getAttribute('id');
					  
					  //获得详情页面
					  if(!detailPage){
					    detailPage = plus.webview.getWebviewById('detail.html');
					  } 
					  
					  //触发详情页面的newsId事件
					  mui.fire(detailPage,'newsId',{
					    id:id
					  });
					    
					//打开详情页面          
					  mui.openWindow({
					    id:'detail.html', 
					  });
					});
				});
			})(mui);
		</script>
	</body>

</html>